$(function () {
  getCapitalData();
});

zijin = 1;

function getCapitalData() {
  const currYear = localStorage.getItem("year");
  const currMon = localStorage.getItem("month");
  const currDept = localStorage.getItem("dept");
  $.get(
    `${API_URL}getdata?budgetYear=${currYear}&budgetMonth=${currMon}&dept=${currDept}&status=2&chartPage=50102`,
    {},
    function (res) {
      let re = eval("(" + res + ")");
      getMonthTrend(re.items[0].charts[1].data);
      let redata = re.items[0].charts[0].data[0];
      getBalance(redata);
      let result1 = `<img src="assets/images/capital/Icon-Wallet@2x.png" ><div class="">
									<p>总金额<span>(${FormatDW(redata.key01)})</span></p>
									<h3>${FormatCash(redata.key01)}</h3>
								</div>`;
      $(".wrapper .total .word .figure").html(result1);
      let result2 = `<div class="title">
								<div class="">
									<h4>年初</h4>
								</div>
							</div><div class="">
								<div class="amount">
									<p>总金额</p>
									<span>（${FormatDW(redata.key04)}）</span>
									<h4>${FormatCash(redata.key04)}</h4>
								</div>
								<div class="items box">
									<div class="">
										<p>现金</p>
										<h5>${FormatCash(redata.key05)}<span>${FormatDW(redata.key05)}</span></h5>
									</div>
									<div class="">
										<p>票据</p>
										<h5>${FormatCash(redata.key06)}<span>${FormatDW(redata.key05)}</span></h5>
									</div>
								</div>
							</div>`;
      $(".wrapper .napes>div.begin").html(result2);
      let result3 = `<div class="title">
								<div class="">
									<h4>流入</h4>
								</div>
								<a href="capitalIncome.html"><img src="assets/images/capital/icon-arrow@2x.png" ></a>
							</div><div class="">
								<div class="amount">
									<div>
										<p>本月金额</p>
										<span>（${FormatDW(redata.key13)}）</span>
										<h4>${FormatCash(redata.key13)}</h4>
									</div>
									<div>
										<p>本年累计金额</p>
										<span>（${FormatDW(redata.key07)}）</span>
										<h4>${FormatCash(redata.key07)}</h4>
									</div>
								</div>
								<div class="items box">
									<img src="assets/images/capital/arrow@2x.png" >
									<div class="">
										<p>现金</p>
										<h5>${FormatCash(redata.key08)}<span>${FormatDW(redata.key08)}</span></h5>
									</div>
									<div class="">
										<p>票据</p>
										<h5>${FormatCash(redata.key09)}<span>${FormatDW(redata.key09)}</span></h5>
									</div>
								</div>
							</div>`;
      $(".wrapper .napes>div.influx").html(result3);
      let result4 = `<div class="title">
								<div class="">
									<h4>流出</h4>
								</div>
								<a href="capitalCost.html"><img src="assets/images/capital/icon-arrow@2x.png" ></a>
							</div><div class="">
								<div class="amount">
									<div>
										<p>本月金额</p>
										<span>（${FormatDW(redata.key14)}）</span>
										<h4>${FormatCash(redata.key14)}</h4>
									</div>
									<div>
										<p>本年累计金额</p>
										<span>（${FormatDW(redata.key10)}）</span>
										<h4>${FormatCash(redata.key10)}</h4>
									</div>
								</div>
								<div class="items box">
									<img src="assets/images/capital/arrow@2x.png" >
									<div class="">
										<p>现金</p>
										<h5>${FormatCash(redata.key11)}<span>${FormatDW(redata.key11)}</span></h5>
									</div>
									<div class="">
										<p>票据</p>
										<h5>${FormatCash(redata.key12)}<span>${FormatDW(redata.key12)}</span></h5>
									</div>
								</div>
							</div>`;
      $(".wrapper .napes>div.outflow").html(result4);
      // let result = `<em class="big">本年计划到款</em>
      // 			<h2>${FormatCash(re.key01)}<span>${FormatDW(re.key01)}</span></h2>`
      // let compare = _compare(re.key02);
      // result += compare;
      // result += `<div class="figureIntro">
      // 				<div class="">
      // 					<i class="big">已认领</i>
      // 					<h5>${FormatCash(re.key03)}<span>${FormatDW(re.key03)}</span></h5>
      // 				</div>
      // 				<div class="">
      // 					<i class="big">已开票</i>
      // 					<h5>${FormatCash(re.key04)}<span>${FormatDW(re.key04)}</span></h5>
      // 				</div>
      // 			</div>`;

      // $('.yearReceive').html(result)

      // getReceiveSurvey(re)
    }
  );
}

// 月度到款情况
function getMonthTrend(re) {
  let liuruData = [];
  let liuchuData = [];
  let yueData = [];
  for (let i = 0; i < re.length; i++) {
    liuruData.push(FormatWYCash(re[i].key02));
    liuchuData.push(FormatWYCash(re[i].key03));
    yueData.push(FormatWYCash(re[i].key04));
  }
  let legendData = ["资金流入", "资金流出", "现金及等价物余额"];
  let seriesData = [
    {
      name: "资金流入",
      barWidth: "32",
      barGap: 0,
      type: "bar",
      data: liuruData,
      itemStyle: {
        color: "#F1416C",
      },
    },
    {
      name: "资金流出",
      barWidth: "32",
      barGap: 0,
      type: "bar",
      data: liuchuData,
      itemStyle: {
        color: "#50CD89",
      },
    },
    {
      name: "现金及等价物余额",
      smooth: false, //平滑曲线显示
      symbol: "circle", //标记的图形为实心圆
      symbolSize: 10, //标记的大小
      showSymbol: false,
      lineStyle: {
        width: 2,
        color: "#165DFF",
      },
      type: "line",
      itemStyle: {
        color: "#165DFF",
        borderColor: "#FFFFFF", //圆点透明 边框
        borderWidth: 2,
        type: "solid", //'dotted'虚线 'solid'实线
      },
      data: yueData,
    },
  ];
  have("monthqs") ? monthTrend("monthqs", seriesData, legendData) : "";
}

function getBalance(data) {
  // console.log(data)
  have("difference") ? balance("difference", data.key02, data.key01) : "";
  let result = `<div class="">
									<p>现金</p>
									<h4>${FormatCash(data.key02)}<span>${FormatDW(data.key02)}</span></h4>
								</div>
								<div class="">
									<p>票据</p>
									<h4>${FormatCash(data.key03)}<span>${FormatDW(data.key03)}</span></h4>
								</div>`;
  $(".wrapper .total .graph .legend").html(result);
}
